import React from "react";
import { Route, Redirect } from "react-router-dom";
import { isLogin } from "../../utils/auth";
//
export default function AuthRoute({ component: Component, ...rest }) {
  // 1.获取用户是否已经登录
  // 2.如果已经登录，正常跳转
  // 3.如果未登录，重定向到登录页
  // const auth = isLogin();
  // return (
  //   auth ?
  //   <Route {...rest} render={({ location }) => {(<Component />)}}/>
  //   :
  //   <Redirect to={{ pathname: "/login"}} />
  // )
  const auth = isLogin();
  return <Route {...rest} render={(props) => {
    const { location } = props
   return auth ? <Component {...props} /> : <Redirect to={{ pathname:'/login', state:{from:location} }} />
  }}/>
}

  
